package com.ruan.controller;

import com.ruan.entity.Discuss;
import com.ruan.entity.R;
import com.ruan.service.DiscussService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName:DiscussController
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/10/7 10:49
 **/
@RestController
@RequestMapping("/discuss")
@Api(tags = "农业知识评论相关接口")
public class DiscussController {

    @Autowired
    private DiscussService discussService;

    @ApiOperation("根据id获取农业知识评论")
    @ApiImplicitParam(name = "knowLedgeId",value = "农业知识id",dataType = "Integer")
    @GetMapping("/getDiscussByKnowledgeId")
    public R<List<Discuss>> getDiscussByKnowledgeId(Integer knowledgeId){
        return discussService.getDiscussByKnowledgeId(knowledgeId);
    }

    @ApiOperation("添加农业知识评论")
    @ApiImplicitParam(name = "discuss",value = "农业知识评论对象",dataType = "Discuss")
    @PostMapping("/addDiscuss")
    @PreAuthorize("hasAuthority('addDiscuss')")
    public R<Void> addDiscuss(@RequestBody Discuss discuss){
        return discussService.addDiscuss(discuss);
    }
}
